<template>
	<view class="content">
		<!-- <nav-header /> -->
		<view class="tab-card flex-row-start" :style="{top: `${getTop()}`}">
			<view class="tab-item" :class="{'tab-item-active': tabId == 1}" @click="setTabId(1)">未完成</view>
			<view class="tab-item" :class="{'tab-item-active': tabId == 2}" @click="setTabId(2)">已完成</view>
		</view>
		<view class="s-input-wrap sinput-fixed-w">
			<view class="s-input-box flex-row sinput-fixed">
				<input auto-focus="true" v-model="inputCode" @confirm="handleInput" class="s-input flex1" placeholder="扫描 / 输入单据号" />
				<image v-if="inputCode" class="s-input-icon clear-icon" src="/static/images/clear.png" @click="handleClear"></image>
				<image class="s-input-icon" src="/static/images/scan.png"></image>
			</view>
		</view>
		<view class="list-card-wrap" style="margin-top: 190rpx;">
			<view v-for="(item,index) in tableData" :key="index" class="list-card" @click="toPage(item)">
				<view class="flex-row-between">
					<navigator class="flex-row" :url="'/pages/outboundAdj/outbound/edit?type=view&id='+item.id">
						<text class="gray-text">单据号</text>
						<text class="black-text-34" style="margin-left: 20rpx;">{{item.bizNo}}</text>
						<uni-icons type="right" size="16" color="#8997A8"></uni-icons>
					</navigator>
				</view>
				<view class="flex-row-between">
					<view class="flex-row">
						<text class="gray-text">货&ensp;主</text>
						<text class="black-text-34" style="margin-left: 20rpx;">{{item.owner}}</text>
					</view>
					<view class="flex-row">
						<text class="gray-text">仓&ensp;库</text>
						<text class="black-text-34" style="margin-left: 20rpx;">{{item.stockCode}}</text>
					</view>
				</view>
				<view class="flex-row-between">
					<view class="flex-row">
						<text class="gray-text">库&ensp;存&ensp;状&ensp;态</text>
						<text class="black-text-34" style="margin-left: 20rpx;">{{getDict(item.stockStatus, erpStockStatus)}}</text>
					</view>
				</view>
				<view class="content flex-row">
					<view class="flex-column flex1">
						<text class="gray-text">总数</text>
						<text class="black-text">{{item.totalQty}}</text>
					</view>
					<view class="split"></view>
					<view class="flex-column flex1">
					</view>
				</view>
				<view v-if="tabId == 1" class="flex-row-between">
					<text class="gray-text">创建时间 {{item.createTime}}</text>
					<view class="flex-row">
						<navigator :url="'/pages/outboundAdj/outbound/edit?id='+item.id" hover-class="other-navigator-hover">
							<view class="botton">出库</view>
						</navigator>

					</view>
				</view>
				<view v-if="tabId == 2" class="">
					<view class="flex-row-between">
						<text class="gray-text">创建时间</text>
						<text class="gray-text">{{item.createTime}}</text>
					</view>
					<view class="flex-row-between">
						<text class="gray-text">完成时间</text>
						<text class="gray-text">{{item.completeTime}}</text>
					</view>
				</view>
			</view>
			<list-footer :total="total" :dataLength="tableData.length"></list-footer>
		</view>
	</view>
</template>

<script>
	import { getDict,getTop } from '@/utils/common.js'
	import {
		getAdjustOutList,
		getInStockBatchInfo,
		complete,
	} from "./api"
	var printModule = uni.requireNativePlugin("pda-print-PdaPrintModule")
	export default {
		data() {
			return {
				inputCode:"",
				getTop,
				// 遮罩层
				loading: true,
				// 查询参数
				queryParams: {
					pageNum: 1,
					pageSize: 10,
				},
				total: 0,
				searchValue: '',
				tabId: 1,
				tableData: [],
				erpStockStatus:[],
				getDict
			}
		},
		onNavigationBarSearchInputChanged(obj){
			if(!obj.text){
				this.queryParams.no = '';
				this.refreshList()
			}
		},
		onNavigationBarSearchInputConfirmed(obj) {
			// obj.text
			this.queryParams.no = obj.text;
			this.refreshList()
		},
		// 上拉加载
		onReachBottom() {
			if (this.tableData.length == this.total) {
				return;
			}
			this.queryParams.pageNum++;
			this.getList();
		},
		onLoad(option) {
			let that = this
			uni.$on('refreshList',function(data){
				that.refreshList()
			})
			this.getDicts("erp_stock_status").then(res => {
			    this.erpStockStatus = res.data;
			});
			this.getList()
		},
		onUnload(){
			uni.$off('refreshList')
		},
		methods: {
			handleClear(){
				this.inputCode = ''
				this.getList('search');
			},
			handleInput(){
				this.getList('search');
			},
			toPage(item) {
				if (this.tabId == 2) {
					this.toDetail(item)
				}
			},
			setTabId(tabId) {
				this.tabId = tabId;
				this.refreshList();
			},
			clearForm() {
				this.form = {
					batchNo: '',
					storehouseLocationNo: '',
					productNo: '',
					productName: '',
					quantity: ''
				}
			},
			refreshList(){
				this.tableData = [];
				this.total = 0;
				this.queryParams.pageNum = 1;
				this.getList();
			},
			getList(type) {
				uni.showLoading({
					title: '加载中...'
				});
				if(this.tabId == 2){
					this.queryParams.searchFinish = 'Y'
				}else{
					this.queryParams.searchFinish = 'N'
				}
				this.queryParams.bizNo = this.inputCode
				getAdjustOutList(this.queryParams).then(res => {
					if(type == 'search'){
						this.tableData = res.rows
					}else{
						this.tableData = this.tableData.concat(res.rows);
						this.total = res.total;
					}
					
					uni.hideLoading();
				});
			},
			submit() {
				if (!this.form.batchNo ) {
					this.$modal.msg("请输入批次号")
				} else if (!this.form.storehouseLocationNo ) {
					this.$modal.msg("请输入库位编码")
				} else if (!this.form.quantity  || this.form.quantity == 0) {
					this.$modal.msg("请输入数量")
				} else {
					this.$modal.loading("入库中...")
					inoutstock({
						...this.form,
						type: 0,
						operation: 0
					}).then(res => {
						this.$modal.closeLoading()
						if (res.code == 200) {
							this.$modal.msgSuccess("入库成功")
							this.clearForm()
						}else{
							res.msg && this.$modal.confirmClose(res.msg)
						}
					})
				}
			},
			// 完成收货任务
			completeTask(item){
				this.$modal.confirm('是否确认完成').then(() => {
					let detailData = [];
					this.$modal.loading("加载中...")
					complete({
						bizNo:item.bizNo
					}).then(res => {
						this.$modal.closeLoading()
						if (res.code == 200) {
							this.$modal.msgSuccess("操作成功");
							setTimeout(()=> {
							this.refreshList();
							}, 1000);
						}else{
							res.msg && this.$modal.confirmClose(res.msg)
						}
					})
				})
			}
		}
	}
</script>

<style lang="scss">
	page {
		background-color: #F8F8F8;
	}
</style>
<style lang="scss" scoped>
	.content {
		// margin: 17rpx 25rpx;
	}
</style>
